<template>
  <el-card>
    <el-table :data="skuList" border style="margin: 10px 0">
      <el-table-column
        type="index"
        label="序号"
        width="80"
        align="center"
      ></el-table-column>
      <el-table-column
        label="名称"
        prop="skuName"
        width="150"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="描述"
        prop="skuDesc"
        width="150"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column label="默认图片" width="150">
        <template #="{ row, $index }">
          <img
            :src="row.skuDefaultImg"
            alt=""
            style="width: 100px; height: 100px"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="重量（g）"
        prop="weight"
        width="150"
      ></el-table-column>
      <el-table-column
        label="价格（元）"
        prop="price"
        width="150"
      ></el-table-column>
      <el-table-column label="操作" width="250" fixed="right">
        <template #="{ row, $index }">
          <el-button type="primary" size="small" icon="top"></el-button>
          <el-button type="primary" size="small" icon="edit"></el-button>
          <el-button type="primary" size="small" icon="infoFilled"></el-button>
          <el-button type="primary" size="small" icon="delete"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[10, 20, 30, 40]"
      :background="true"
      layout="prev, pager, next, jumper, ->, sizes, total"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="getSkuList"
    />
  </el-card>
</template>

<script setup lang="ts" name="Sku">
import { ref, onMounted } from 'vue'
import { getSkuInfoListByPageApi } from '@/api/product/sku'
import type { SkuResponseData, SkuData } from '@/api/product/sku/type'

const currentPage = ref<number>(1)
const pageSize = ref<number>(10)
const total = ref<number>(0)
const skuList = ref<SkuData[]>([])
// 方法
const handleSizeChange = (pageSizer = 10) => {
  getSkuList()
}
const getSkuList = async (pager = 1) => {
  currentPage.value = pager
  const res: SkuResponseData = await getSkuInfoListByPageApi(
    currentPage.value,
    pageSize.value,
  )
  if (res.code == 200) {
    skuList.value = res.data.records
    total.value = res.data.total
  }
}

onMounted(() => {
  getSkuList()
})
</script>

<style scoped lang="scss"></style>
